package com.example.permissionservice.common;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
@Schema(description = "响应结果包装类")
public class Result<T> {
    @Schema(description = "响应码，如 200 表示成功")
    private Integer code;

    @Schema(description = "提示信息，如成功、失败原因等")
    private String message;

    @Schema(description = "响应数据")
    private T data;

    public static <T> Result<T> success(T data) {
        Result<T> r = new Result<>();
        r.setCode(200);
        r.setMessage("Success");
        r.setData(data);
        return r;
    }

    public static <T> Result<T> success() {
        Result<T> r = new Result<>();
        r.setCode(200);
        r.setMessage("Success");
        return r;
    }

    public static <T> Result<T> failure(String message) {
        Result<T> r = new Result<>();
        r.setCode(400);
        r.setMessage(message);
        r.setData(null);
        return r;
    }

    public static <T> Result<T> error(String message) {
        Result<T> r = new Result<>();
        r.setCode(500);
        r.setMessage(message);
        r.setData(null);
        return r;
    }
}